<?php
declare (strict_types = 1);

namespace app\home\middleware;

use think\exception\ValidateException;
use liliuwei\think\Jump;
class CheckLogin
{
    use Jump;
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        //
        try {
            //过滤
            $data=$request->all('','trim');
            unset($data['ml']);
            validate(\app\home\validate\CheckLogin::class)->check($data);
            if($data['password']!=$data['repassword']) {
                 $this->error('密码不一致');
            }
            unset($data['repassword']);
           // dd($data);
            return $next($request);
        }catch (ValidateException $e) {
            // 验证失败 输出错误信息
                $this->error($e->getError());
        }
    }

}
